package com.Trainer.TrainerInterface;

import com.data.TrainerData;
import javax.swing.*;
import java.awt.*;

public class TrainerBottomLeftPanel extends JPanel {
    //属性
    JButton confirmBtn;
    JButton nextBtn;
    JLabel ansLabel;
    JLabel operand1;
    JLabel operand2;
    JLabel operator1;
    JLabel operator2;
    JTextField ansText;
    JButton ansJudge;

    //构造器
    public TrainerBottomLeftPanel(int x,int y,int weight,int height,TrainerData data) {
        confirmBtn = new JButton("评审");
        nextBtn = new JButton("下一题");
        ansLabel = new JLabel("答案:");
        operand1 = new JLabel(""+data.getOp1());
        operand2 = new JLabel(""+data.getOp2());
        operator1 = new JLabel(data.getOpLabel());
        operator2 = new JLabel("=");
        ansText = new JTextField();
        ansJudge = new JButton();

        //标签修饰
        setLabel(ansLabel,200,180,50,50,20);
        setLabel(operand1,120,80,100,50,40);
        setLabel(operand2,310,80,100,50,40);
        setLabel(operator1,250,90,30,30,40);
        setLabel(operator2,440,90,30,30,40);


        //输入框修饰
        ansText.setBounds(260,180,100,50);
        ansText.setFont(new Font("微软雅黑",Font.PLAIN,40));

        //按钮修饰
        confirmBtn.setBounds(110,280,150,60);
        confirmBtn.setFont(new Font("微软雅黑",Font.PLAIN,30));
        nextBtn.setBounds(360,280,150,60);
        nextBtn.setFont(new Font("微软雅黑",Font.PLAIN,30));
        ansJudge.setBounds(400,180,150,50);
        ansJudge.setFont(new Font("微软雅黑",Font.PLAIN,30));
        ansJudge.setText("?");
        //布局
        setLayout(null);
        //setBackground(Color.MAGENTA);
        setBounds(x,y,weight,height);

        //组件加入
        add(ansLabel);
        add(operand1);
        add(operator1);
        add(operand2);
        add(operator2);
        add(ansText);
        add(confirmBtn);
        add(nextBtn);
        add(ansJudge);

    }

    public JButton getAnsJudge() {
        return ansJudge;
    }

    public void setLabel(JLabel label, int x, int y, int weight, int height, int size){
        label.setBounds(x,y,weight,height);
        label.setOpaque(true);
        label.setFont(new Font("微软雅黑",Font.PLAIN,size));
        label.setHorizontalAlignment(SwingConstants.CENTER);
        //label.setBackground(Color.YELLOW);
    }

    public int submit(){
        try {
            return Integer.parseInt(ansText.getText());
        }catch (Exception e){
            return -1;
        }
    }

    public JTextField getAnsText() {
        return ansText;
    }

    public JLabel getOperand1() {
        return operand1;
    }

    public JLabel getOperand2() {
        return operand2;
    }

    public JLabel getOperator1() {
        return operator1;
    }

    public JButton getConfirmBtn() {
        return confirmBtn;
    }

    public JButton getNextBtn() {
        return nextBtn;
    }
}
